//
//  ByNetJobApi.m
//  jmsfhz_ios
//
//  Created by pro on 16/8/3.
//  Copyright © 2016年 pro. All rights reserved.
//

#import "ByNetJobApi.h"

#import "ByNetJobModel.h"               // 简历model
@implementation ByNetJobApi

/** 岗位查询 */
+ (void)jobQuery:(ByNetParamsModel *)model
         success:(void(^)(ByNetBaseResult *result))success
         failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"By_CompanyEmploy_query";
    static NSInteger apiVersion = 103;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%.0lf%d", [NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.page_num forKey:@"page_num"];
    [params setObject:model.page_size forKey:@"page_size"];
    if (model.keywords) {
        [params setObject:model.keywords forKey:@"keywords"];
    }
    
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
//           DLog(@"******** 岗位获取 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取成功";
           ByNetJobModel *model = [[ByNetJobModel alloc] initContentWithDic:responseObject];
           result.data = model;
           result.notify_id = notifyID;

           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** 岗位查询 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert alertError:result.msg];
           }
       }];
}

/** 投简历 */
+ (void)jobSend:(ByNetParamsModel *)model
        success:(void(^)(ByNetBaseResult *result))success
        failure:(void(^)(ByNetBaseResult *result))failure {
    
    
    static NSString *apiType = @"By_CompanyEmploy_apply";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%.0lf%d", [NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.id forKey:@"id"];
    [params setObject:model.uid forKey:@"uid"];
    
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeString
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           NSLog(@"投简历原始数据:%@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"投简历成功";
           result.data = responseObject;
           result.notify_id = notifyID;

           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** 投简历 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert alertError:result.msg];
           }
       }];
}

/** 我投过的 */
+ (void)jobThatMySend:(ByNetParamsModel *)model
              success:(void(^)(ByNetBaseResult *result))success
              failure:(void(^)(ByNetBaseResult *result))failure {
    
    static NSString *apiType = @"By_CompanyApplyInfo_apply";
    static NSInteger apiVersion = 100;
    int rand = arc4random() % 1000;
    
    NSString *requestId = [NSString stringWithFormat:@"%.0lf%d", [NSDate currentDateTimeInterval], rand];
    
    // 拼接参数
    NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
    [params setObject:model.uid forKey:@"uid"];
    [params setObject:model.page_num forKey:@"page_num"];
    [params setObject:model.page_size forKey:@"page_size"];
    
    
    // 返回的responseObject 可能是字符串也可能是字典
    [self post:requestId
       apiType:apiType
      dataType:ByNetDataTypeDictionary
     apiVerson:apiVersion
        params:params
       success:^(NSURLSessionDataTask *operation, id responseObject, NSString *notifyID) {
           
           DLog(@"******** 我投过的简历 -> 成功: %@", responseObject);
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = 0;
           result.msg = @"获取成功";
           ByNetJobModel *model = [[ByNetJobModel alloc] initContentWithDic:responseObject];
           result.data = model;
           result.notify_id = notifyID;

           if(success) {
               success(result);
           }
           
       } failure:^(NSURLSessionDataTask *operation, NSError *error){
           
           DLog(@"******** 我投过的简历，获取 -> 失败: %@", error);
           
           ByNetBaseResult *result = [[ByNetBaseResult alloc] init];
           result.code = error.code;
           result.msg = error.domain;
           result.data = error.localizedDescription;
           if(failure) {
               failure(result);
           } else {
               [ByCoreToolAlert alertError:result.msg];
           }
       }];
}


@end
